/********************************************************
 * Filename: TclPreferences.java
 * Author: LMU
 * Program: TUnit
 * Description: Set the Preferences for TUnit.  
 * Revision History:
 * 20060512: Initial Revision.
 * *****************************************************/

package edu.lmu.cs.tUnit.preferences;

import org.eclipse.jface.preference.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbench;
import org.eclipse.jface.preference.IPreferenceStore;

import edu.lmu.cs.tUnit.plugin.TUnitPlugin;

public class TclPreferences extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
	
	public static final int TCLKEYWORD1 = SWT.COLOR_BLUE;
	public static final int TCLKEYWORD2 = SWT.COLOR_DARK_BLUE;
	public static final int COMMENT = SWT.COLOR_DARK_GREEN;
	public static final int STRING = SWT.COLOR_DARK_CYAN;
	public static final int DEFAULT = SWT.COLOR_BLACK;
	public static final int BACKGROUND = SWT.COLOR_WHITE;
	
	public TclPreferences() {
		super(GRID);
		setPreferenceStore(TUnitPlugin.getDefault().getPreferenceStore());
	}
/**
 * Sets the default values of the preferences.
 */
	public void initializeDefaults() {
		Display display = Display.getCurrent();
		Color cTCLKEYWORD1 = display.getSystemColor(TCLKEYWORD1);
		Color cTCLKEYWORD2 = display.getSystemColor(TCLKEYWORD2);
		Color cCOMMENT = display.getSystemColor(COMMENT);
		Color cSTRING = display.getSystemColor(STRING);
		Color cDEFAULT = display.getSystemColor(DEFAULT);
		Color cBACKGROUND = display.getSystemColor(BACKGROUND);
		
		IPreferenceStore store = TUnitPlugin.getDefault().getPreferenceStore();
		PreferenceConverter.setDefault(store, TclPreferencesConstants.P_KEYWORDCOLOR1, cTCLKEYWORD1.getRGB());
		PreferenceConverter.setDefault(store, TclPreferencesConstants.P_KEYWORDCOLOR2, cTCLKEYWORD2.getRGB());
		PreferenceConverter.setDefault(store, TclPreferencesConstants.P_COMMENTCOLOR, cCOMMENT.getRGB());
		PreferenceConverter.setDefault(store, TclPreferencesConstants.P_STRINGCOLOR, cSTRING.getRGB());
		PreferenceConverter.setDefault(store, TclPreferencesConstants.P_DEFAULTCOLOR, cDEFAULT.getRGB());
		PreferenceConverter.setDefault(store, TclPreferencesConstants.P_BACKGROUNDCOLOR, cBACKGROUND.getRGB());
		store.setDefault(TclPreferencesConstants.P_USE_SPACES_FOR_TABS, false);
		store.setDefault(TclPreferencesConstants.P_NUMBERSPACES, 3);
		store.setDefault(TclPreferencesConstants.P_CONTENTASSIST, true);
	}
	
	/**
	 * Creates the field editors. Field editors are abstractions of
	 * the common GUI blocks needed to manipulate various types
	 * of preferences. Each field editor knows how to save and
	 * restore itself.
	 */
	public void createFieldEditors() {
		
	    addField(new ColorFieldEditor(TclPreferencesConstants.P_KEYWORDCOLOR1, "&Primary Keyword Color:", getFieldEditorParent()));
	    addField(new ColorFieldEditor(TclPreferencesConstants.P_KEYWORDCOLOR2, "&Secondary Keyword Color:", getFieldEditorParent()));
	    addField(new ColorFieldEditor(TclPreferencesConstants.P_COMMENTCOLOR, "&Comment Color:", getFieldEditorParent()));
	    addField(new ColorFieldEditor(TclPreferencesConstants.P_STRINGCOLOR, "&String Color:", getFieldEditorParent()));
	    addField(new ColorFieldEditor(TclPreferencesConstants.P_DEFAULTCOLOR, "&Default Color:", getFieldEditorParent()));
	    addField(new ColorFieldEditor(TclPreferencesConstants.P_BACKGROUNDCOLOR, "&Background Color:", getFieldEditorParent()));
	    addField(new BooleanFieldEditor(TclPreferencesConstants.P_USE_SPACES_FOR_TABS, "&Use Spaces to Replace Tabs", getFieldEditorParent()));
	    addField(new IntegerFieldEditor(TclPreferencesConstants.P_NUMBERSPACES, "&Number of Spaces to Replace Tab Characters:", getFieldEditorParent()));
	    addField(new BooleanFieldEditor(TclPreferencesConstants.P_CONTENTASSIST, "&Allow for Content Assistance", getFieldEditorParent()));
	}
	
	public void init(IWorkbench workbench) {
		
	}
}
